<?php
//导入扩展函数库
load('extend');
/**
 * 上传文件方法
 */
function upload() {
	import ( 'ORG.Net.UploadFile' );
	$upload = new UploadFile (); // 实例化上传类
	$upload->maxSize = 3145728; // 设置附件上传大小
	$upload->allowExts = array (
			'jpg',
			'gif',
			'png',
			'jpeg'
	); // 设置附件上传类型
	$upload->savePath = './Public/Uploads/';
	$upload->thumb = true;
	$upload->thumbMaxWidth = 100;
	$upload->thumbMaxHeight = 100;
	
	if (! $upload->upload ()) {
		$message = $upload->getErrorMsg();
		$data = array(
				'error'=>1,
				'message'=>$message
		);
	} else {
		$info =  $upload->getUploadFileInfo();
		$path = $info[0]['savepath'].$info[0]['savename'];
		$thumb = $info[0]['savepath'].'thumb_'.$info[0]['savename'];	
		$data = array(
				'error'=>0,
				'name'=>$info[0]['name'],
				'url'=>$path,
				'thumb'=>$thumb
		);
	}
	
	return $data;
}